package cn.bluethink.eguan.statistics.entity;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import cn.bluethink.eguan.model.core.EgTavern;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.model.okrtask.EgOkrTask;
import cn.bluethink.eguan.model.okrtask.EgTaskKR;
import cn.bluethink.eguan.okrtask.entity.EgTaskKREntity;

/**
 * @title 天眼模块 - 任务实体
 * @Copyright 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1
 *
 * @note 修订历史： （1）liuxn于2019年1月29日构建初始版本0.1
 */
public class OKRTaskEntity {

	/**
	 * 任务ID
	 */
	private Long tid;
	
	// 任务名称
	private String tname;
	
	// 任务完成时间
	private Date ftime;
	
	// 任务优先级
	private Integer priority;
	
	// 任务状态
	private Integer status;
	
	// 目标类型
	private Integer timing;
	
	// 创建者Id
	private Long cuid;
	
	// 创建者名称
	private String cuname;
	
	// 任务执行人
	private Long douid;
	
	// 任务执行人名称
	private String douname;
	
	// 任务截止日期
	private Date tasketime;
	
	// 任务所属驿馆ID
	private Long egid;
	
	// 驿馆名称
	private String egname;
	
	// 驿馆图标
	private String egicon;
	
	// 任务关键项列表
	private List<EgTaskKREntity> taskkrList;

	public OKRTaskEntity() {
		
	}
	
	/**
	 * 转换为工作任务
	 * @param entity
	 * @return
	 */
	public EgOkrTask createTask() {
		EgOkrTask task = new EgOkrTask(tid, tname, null);
		task.setFtime(ftime);
		task.setPriority(priority);
		task.setStatus(status);
		task.setTiming(timing);
		EgUser cuser = new EgUser(cuid, null, null);
		task.setCuser(cuser);
		
		// 设置被指派人
		if(douid != null && douid > 0) {
			EgUser user = new EgUser(douid, douname, null);
			task.setDouser(user);
		}
		task.setEtime(tasketime);
		// 设置驿馆
		if(egid != null && egid > 0) {
			EgTavern tavern = new EgTavern(egid, egname, egicon);
			task.setPos(tavern);
		}
		// 设置关键结果列表
		if(taskkrList != null && taskkrList.size() > 0) {
			List<EgTaskKR> taskkrs = taskkrList.stream().map(t -> t.createKeyResult()).collect(Collectors.toList());
			task.setTaskkrList(taskkrs);
		}
		return task;
	}
	
	public Long getTid() {
		return tid;
	}

	public void setTid(Long tid) {
		this.tid = tid;
	}

	public String getTname() {
		return tname;
	}

	public void setTname(String tname) {
		this.tname = tname;
	}

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getTiming() {
		return timing;
	}

	public void setTiming(Integer timing) {
		this.timing = timing;
	}

	public Long getDouid() {
		return douid;
	}

	public void setDouid(Long douid) {
		this.douid = douid;
	}

	public String getDouname() {
		return douname;
	}

	public void setDouname(String douname) {
		this.douname = douname;
	}

	public Date getTasketime() {
		return tasketime;
	}

	public void setTasketime(Date tasketime) {
		this.tasketime = tasketime;
	}

	public Long getEgid() {
		return egid;
	}

	public void setEgid(Long egid) {
		this.egid = egid;
	}

	public String getEgname() {
		return egname;
	}

	public void setEgname(String egname) {
		this.egname = egname;
	}

	public List<EgTaskKREntity> getTaskkrList() {
		return taskkrList;
	}

	public void setTaskkrList(List<EgTaskKREntity> taskkrList) {
		this.taskkrList = taskkrList;
	}

	public Date getFtime() {
		return ftime;
	}

	public void setFtime(Date ftime) {
		this.ftime = ftime;
	}

	public String getEgicon() {
		return egicon;
	}

	public void setEgicon(String egicon) {
		this.egicon = egicon;
	}

	public Long getCuid() {
		return cuid;
	}

	public void setCuid(Long cuid) {
		this.cuid = cuid;
	}

	public String getCuname() {
		return cuname;
	}

	public void setCuname(String cuname) {
		this.cuname = cuname;
	}
	
}
